using System;
using System.Collections.Generic;
using System.Text;
using Fodee.DataEntity;
using System.Data.Common;
using System.Data;

namespace Fodee.DataAccess
{
public class fodBillDA : FodeeDABase
{
public fodBillDA()
{
}

public bool Insert(FodeeDataSet ds, DbTransaction dbTransaction)
{
DbCommand command = Db.GetStoredProcCommand("P_fod_Bill_I");
Db.AddOutParameter(command, "@ID", System.Data.DbType.Int32, 8);
Db.AddInParameter(command, "@BillNum", System.Data.DbType.String, "BillNum", DataRowVersion.Current);
Db.AddInParameter(command, "@BillAmount", System.Data.DbType.Decimal, "BillAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillFinalAmount", System.Data.DbType.Decimal, "BillFinalAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillPaidAmount", System.Data.DbType.Decimal, "BillPaidAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillChangeAmount", System.Data.DbType.Decimal, "BillChangeAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillPledge", System.Data.DbType.Decimal, "BillPledge", DataRowVersion.Current);
Db.AddInParameter(command, "@BillDiscountAmount", System.Data.DbType.Decimal, "BillDiscountAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillFreeAmount", System.Data.DbType.Decimal, "BillFreeAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillReduceAmount", System.Data.DbType.Decimal, "BillReduceAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillServiceAmount", System.Data.DbType.Decimal, "BillServiceAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillReturnAmount", System.Data.DbType.Decimal, "BillReturnAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillIsReciept", System.Data.DbType.Boolean, "BillIsReciept", DataRowVersion.Current);
Db.AddInParameter(command, "@BillRemarks", System.Data.DbType.String, "BillRemarks", DataRowVersion.Current);
Db.AddInParameter(command, "@VersionNo", System.Data.DbType.Byte, "VersionNo", DataRowVersion.Current);
Db.AddInParameter(command, "@CreatedBy", System.Data.DbType.Int32, "CreatedBy", DataRowVersion.Current);
Db.AddInParameter(command, "@CreatedTime", System.Data.DbType.DateTime, "CreatedTime", DataRowVersion.Current);
Db.AddInParameter(command, "@UpdatedBy", System.Data.DbType.Int32, "UpdatedBy", DataRowVersion.Current);
Db.AddInParameter(command, "@UpdatedTime", System.Data.DbType.DateTime, "UpdatedTime", DataRowVersion.Current);
int result = Db.UpdateDataSet(ds, ds.fod_Bill.TableName, command, null, null, dbTransaction);
 if (result > 0)
return true;
return false;
}

public int Add(FodeeDataSet ds, DbTransaction dbTransaction)
{
DbCommand command = Db.GetStoredProcCommand("P_fod_Bill_I");
Db.AddOutParameter(command, "@ID", System.Data.DbType.Int32, 8);
Db.AddInParameter(command, "@BillNum", System.Data.DbType.String, "BillNum", DataRowVersion.Current);
Db.AddInParameter(command, "@BillAmount", System.Data.DbType.Decimal, "BillAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillFinalAmount", System.Data.DbType.Decimal, "BillFinalAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillPaidAmount", System.Data.DbType.Decimal, "BillPaidAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillChangeAmount", System.Data.DbType.Decimal, "BillChangeAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillPledge", System.Data.DbType.Decimal, "BillPledge", DataRowVersion.Current);
Db.AddInParameter(command, "@BillDiscountAmount", System.Data.DbType.Decimal, "BillDiscountAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillFreeAmount", System.Data.DbType.Decimal, "BillFreeAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillReduceAmount", System.Data.DbType.Decimal, "BillReduceAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillServiceAmount", System.Data.DbType.Decimal, "BillServiceAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillReturnAmount", System.Data.DbType.Decimal, "BillReturnAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillIsReciept", System.Data.DbType.Boolean, "BillIsReciept", DataRowVersion.Current);
Db.AddInParameter(command, "@BillRemarks", System.Data.DbType.String, "BillRemarks", DataRowVersion.Current);
Db.AddInParameter(command, "@VersionNo", System.Data.DbType.Byte, "VersionNo", DataRowVersion.Current);
Db.AddInParameter(command, "@CreatedBy", System.Data.DbType.Int32, "CreatedBy", DataRowVersion.Current);
Db.AddInParameter(command, "@CreatedTime", System.Data.DbType.DateTime, "CreatedTime", DataRowVersion.Current);
Db.AddInParameter(command, "@UpdatedBy", System.Data.DbType.Int32, "UpdatedBy", DataRowVersion.Current);
Db.AddInParameter(command, "@UpdatedTime", System.Data.DbType.DateTime, "UpdatedTime", DataRowVersion.Current);
Db.UpdateDataSet(ds, ds.fod_Bill.TableName, command, null, null, dbTransaction);
int result = int.Parse(Db.GetParameterValue(command, "@ID").ToString());
return result;
}

public bool Update(FodeeDataSet ds, DbTransaction dbTransaction)
{
DbCommand command = Db.GetStoredProcCommand("P_fod_Bill_U");
Db.AddInParameter(command, "@ID", System.Data.DbType.Int32, "ID", DataRowVersion.Current);
Db.AddInParameter(command, "@BillNum", System.Data.DbType.String, "BillNum", DataRowVersion.Current);
Db.AddInParameter(command, "@BillAmount", System.Data.DbType.Decimal, "BillAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillFinalAmount", System.Data.DbType.Decimal, "BillFinalAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillPaidAmount", System.Data.DbType.Decimal, "BillPaidAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillChangeAmount", System.Data.DbType.Decimal, "BillChangeAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillPledge", System.Data.DbType.Decimal, "BillPledge", DataRowVersion.Current);
Db.AddInParameter(command, "@BillDiscountAmount", System.Data.DbType.Decimal, "BillDiscountAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillFreeAmount", System.Data.DbType.Decimal, "BillFreeAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillReduceAmount", System.Data.DbType.Decimal, "BillReduceAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillServiceAmount", System.Data.DbType.Decimal, "BillServiceAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillReturnAmount", System.Data.DbType.Decimal, "BillReturnAmount", DataRowVersion.Current);
Db.AddInParameter(command, "@BillIsReciept", System.Data.DbType.Boolean, "BillIsReciept", DataRowVersion.Current);
Db.AddInParameter(command, "@BillRemarks", System.Data.DbType.String, "BillRemarks", DataRowVersion.Current);
Db.AddInParameter(command, "@VersionNo", System.Data.DbType.Byte, "VersionNo", DataRowVersion.Current);
Db.AddInParameter(command, "@CreatedBy", System.Data.DbType.Int32, "CreatedBy", DataRowVersion.Current);
Db.AddInParameter(command, "@CreatedTime", System.Data.DbType.DateTime, "CreatedTime", DataRowVersion.Current);
Db.AddInParameter(command, "@UpdatedBy", System.Data.DbType.Int32, "UpdatedBy", DataRowVersion.Current);
Db.AddInParameter(command, "@UpdatedTime", System.Data.DbType.DateTime, "UpdatedTime", DataRowVersion.Current);
int result = Db.UpdateDataSet(ds, ds.fod_Bill.TableName, null, command, null, dbTransaction);
 if (result > 0)
return true;
return false;
}

public bool Delete(int id, DbTransaction dbTransaction)
{
DbCommand command = Db.GetStoredProcCommand("P_fod_Bill_D");
Db.AddInParameter(command, "@ID", System.Data.DbType.Int32, id);
int result = Db.ExecuteNonQuery(command, dbTransaction);
 if (result > 0)
return true;
return false;
}

 public FodeeDataSet GetByID(int id)
{
FodeeDataSet ds = new FodeeDataSet();
DbCommand command = Db.GetStoredProcCommand("P_fod_Bill_S");
Db.AddInParameter(command, "@ID", System.Data.DbType.Int32, id);
Db.LoadDataSet(command, ds,ds.fod_Bill.TableName);
return ds;
}

 public FodeeDataSet GetAll()
{
FodeeDataSet ds = new FodeeDataSet();
DbCommand command = Db.GetStoredProcCommand("P_fod_Bill_A");
Db.LoadDataSet(command, ds,ds.fod_Bill.TableName);
return ds;
}


}
}


